package com.example.helloworld.fragment;

import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.helloworld.R;
import com.example.helloworld.adapter.LatestContactsFragmentAdapter;
import com.example.helloworld.base.BaseFragment;

public class LatestContactsFragment extends BaseFragment {

    private ListView listView;

    private String[] list;

    @Override
    protected View initView() {
        Log.i("LatestContactsFragment", "最近联系人页面被初始化...");
        View view = View.inflate(context, R.layout.latest_contacts_fragment, null);
        listView = view.findViewById(R.id.latest_contacts_list);
        //设置listView里每个item的点击事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String checkData = list[position];
                //提示信息
                Toast.makeText(context, "checkData=" + checkData, Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }

    @Override
    protected void initData() {
        super.initData();
        Log.i("LatestContactsFragment", "最近联系人的数据加载了..");
        //准备数据
        list = new String[]{
                "张三",
                "李四",
                "王五",
                "赵六",
                "小红",
                "小花花",
                "张三",
                "李四",
                "王五",
                "赵六",
                "小红",
                "小花花",
                "张三",
                "李四",
                "王五",
                "赵六",
                "小红",
                "小花花",
                "......"
        };

        //设置适配器
        listView.setAdapter(new LatestContactsFragmentAdapter(context, list));
    }
}
